# 1、导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
from time import sleep

# 2、实例化浏览器对象
driver_path = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/geckodriver.exe"
service = Service(executable_path=driver_path)
driver = webdriver.Firefox(service=service)

# 3、打开页面
driver.get("file:///E:/project/learn-python/html%E5%9F%BA%E7%A1%80/3-%E8%A1%A8%E5%8D%95%E6%8F%90%E4%BA%A4.html")

# TODO 元素操作
# 4、需求：
# 01 通过脚本执行输入用户名：admin，密码：123456，电话号码：18611111111，电子邮箱：123@qq.com
driver.find_element(By.ID, "user").send_keys("admin")
driver.find_element(By.ID, "pwd").send_keys("123456")
tel = driver.find_element(By.ID, "tel")
tel.send_keys("18611111111")
driver.find_element(By.ID, "emai").send_keys("123@qq.com")

# 02 间隔3秒，修改电话号码：18600000000
time.sleep(3)
tel.clear()
tel.send_keys("18600000000")

# 03 间隔3秒，点击注册按钮
time.sleep(3)
driver.find_element(By.CSS_SELECTOR, "button").click()

# 5、展示效果
time.sleep(2)

# 6、关闭浏览器
driver.quit()

# TODO 浏览器操作
# 2、实例化浏览器对象
'''
driver.get("http://www.baidu.com")

# 3、需求
# ① 最大化浏览器窗口
driver.maximize_window()

# ② 设置浏览器窗口大小
driver.set_window_size(300, 300)

# ③ 设置浏览器窗口位置
driver.set_window_position(100, 0)

driver.find_element(By.ID, "kw").send_keys("黑马马")
driver.find_element(By.ID, "su").click()
time.sleep(2)

# ④ 后退
driver.back()
time.sleep(2)

# ⑤ 前进
driver.forward()
time.sleep(2)

# ⑥ 刷新
driver.refresh()

# ⑦ 关闭当前窗口
driver.close()

# ⑧ 关闭浏览器驱动对象
driver.quit()
'''

driver.get("file:///E:/project/learn-python/html%E5%9F%BA%E7%A1%80/3-%E8%A1%A8%E5%8D%95%E6%8F%90%E4%BA%A4.html")

# ⑨ 获取页面 title
print("页面标题:", driver.title)

# ⑩ 获取当前页面 url
print("页面地址", driver.current_url)